﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Objects.DataClasses;
using System.Data.Objects;
using DA = System.ComponentModel.DataAnnotations;

namespace ZhQuiz.Models
{
    public partial class SiteDb : ObjectContext
    {
        public static readonly Guid APPID = new Guid("273f9136-97a7-4926-a740-18a89538c817");
        public long LastIDSeed = 0;
        public long LastIDFix = 0;
        static DateTime ZeroTime = new DateTime(2012, 1, 1);
        object newidlocker = new object();
        public string NewID()
        {
            long ts = (long)(DateTime.Now - ZeroTime).TotalSeconds;
            if (ts > LastIDSeed)
            {
                lock (newidlocker)
                {
                    if (ts > LastIDSeed)
                    {
                        LastIDFix = 0;
                        LastIDSeed = ts;
                    }
                }
            }
            return (LastIDSeed * 1000 + (LastIDFix++)).ToString().TrimEnd('0');

        }

        public ObjectSet<T> GetModelByName<T>(string name) where T : class
        {
            var mo = this.GetType().GetProperty(name).GetValue(this, null);
            var m = mo as ObjectSet<T>;
            return m;
        }

        public void DeleteAll(object[] objs)
        {
            foreach (var obj in objs)
            {
                this.DeleteObject(obj);
            }
        }
    }

    public partial class aspnet_Users : EntityObject
    {
        //ext method here
    }

}